home *** CD-ROM | disk | FTP | other *** search
/ IRIX Installation Tools & Overlays 2002 November / SGI IRIX Installation Tools & Overlays 2002 November - Disc 4.iso / dist / cluster_admin.idb / var / cluster / ha / diags / filesystem.pl.z / filesystem.pl
Perl Script  |  2002-10-15  |  8KB  |  243 lines

  1. #!/usr/sbin/perl
  2. #                                                                         
  3. #  Copyright (C) 1998, Silicon Graphics, Inc.                             
  4. #  All Rights Reserved.                                                   
  5. #                                                                         
  6. #  UNPUBLISHED -- Rights reserved under the copyright laws of the United  
  7. #  States.  Use of a copyright notice is precautionary only and does not  
  8. #  imply publication or disclosure.                                       
  9. #                                                                         
  10. #  THIS SOFTWARE CONTAINS CONFIDENTIAL AND PROPRIETARY INFORMATION OF     
  11. #  SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, DISTRIBUTION, OR 
  12. #  DISCLOSURE IS STRICTLY PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN    
  13. #  PERMISSION OF SILICON GRAPHICS, INC.                                   
  14. #                                                                         
  15. #  U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND                               
  16. #  Use, duplication or disclosure by the Government is subject to         
  17. #  restrictions as set forth in FAR 52.227.19(c)(2) or subparagraph       
  18. #  (c)(1)(ii) of the Rights in Technical Data and Computer Software       
  19. #  clause at DFARS 252.227-7013 and/or in similar or successor clauses    
  20. #  in the FAR, or the DOD or NASA FAR Supplement.  Unpublished-- rights   
  21. #  reserved under the copyright laws of the United States.                
  22. #  Contractor/manufacturer is Silicon Graphics, Inc.,                     
  23. #  2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.                 
  24. #
  25.  
  26. # filesystem
  27. #
  28. # Get all resources for a particular type
  29. # and run the tests against that resource.
  30.  
  31. require "$LibDiagsPath/constants.pl";
  32. require "$LibDiagsPath/libdiags.pl";
  33. require "$LibDiagsPath/recurse.pl";
  34.  
  35. sub filesystem {
  36.   local ($machine_name, $resource) = @_;
  37.   local ($this);
  38.   local (@list);
  39.   local ($retv)=$CD_SUCCESS;
  40.  
  41.   &LogEntry();
  42.   &Verbose("Running resource type %s tests on node %s",
  43.        $FILESYSTEM, $machine_name);
  44.  
  45.   if ($resource eq "ALL") {
  46.     @list=&GetResFromResType($machine_name, $FILESYSTEM);
  47.     if (scalar(@list) < 1) {
  48.       &Failure("No resources found for type %s",$FILESYSTEM);
  49.       return $CD_FAILURE;
  50.     }
  51.     foreach $this (@list) {
  52.       $retv=&TestFilesystem($machine_name,$this);
  53.  
  54.       # If the DESTRUCTIVE flag is set ...
  55.       if ($DESTRUCTIVE) {
  56.     if (&Execfilesystem($machine_name,$this) == $CD_FAILURE) {
  57.           &Failure("Resource %s of resource type %s failed",$this,
  58.                $FILESYSTEM);
  59.           $retv=$CD_FAILURE;
  60.     }
  61.       }
  62.       &ExitStatus($retv);
  63.     }
  64.   }else {
  65.     # We have been given the resource name.
  66.     $retv=&TestFilesystem($machine_name, $resource);
  67.  
  68.     # If the DESTRUCTIVE flag is set ...
  69.     if ($DESTRUCTIVE) {
  70.     if (&Execfilesystem($machine_name,$resource) == $CD_FAILURE) {
  71.         &Failure("Resource %s of resource type %s failed",$resource,
  72.              $FILESYSTEM);
  73.         $retv=$CD_FAILURE;
  74.     }
  75.     }
  76.     &ExitStatus($retv);
  77.   }
  78.   return $retv;
  79.  
  80. }
  81.  
  82. sub Execfilesystem {
  83.     local ($node, $resource) = @_;
  84.     local (@depend1, $dependency1, $cnt1);
  85.     local ($retv);
  86.     &LogEntry();
  87.  
  88.     &Status("Starting resource %s of resource type %s on node %s",
  89.          $resource,$FILESYSTEM,$node);
  90.  
  91.     
  92.     # Only execute the destructive tests on this node.
  93.     if (!&OnTheSameNode($node)) {
  94.     &Notice("Can only execute the resource destructive tests on local host");
  95.     &Log("Can only execute the resource destructive tests on local host %s/%s",
  96.           $this_host, $NodeToHost{$node});
  97.     return $CD_SUCCESS;
  98.     }
  99.  
  100.     @depend1=&GetResDependency($node,$FILESYSTEM,$resource);
  101.     if (scalar(@depend1) < 1) {
  102.     &Failure("No dependencies returned for resource %s of resource type %s",
  103.          $resource,$FILESYSTEM);
  104.     return $CD_FAILURE;
  105.     }
  106.     
  107.     # Load all dependencies and start them.
  108.     $cnt1=0;
  109.     foreach $dependency1 (@depend1) {
  110.         # Check that the dependency is set, if so start it
  111.         if ($dependency1=~/$VOLUME/) {
  112.         $retv=ExecuteScript($node,$depend1[$cnt1+1],$VOLUME,$HA_START);
  113.         if ( $retv == 0 ) {
  114.         &Failure("Cannot start $FILESYSTEM resource dependency $depend1[$cnt1+1] of type $VOLUME");
  115.         return $CD_FAILURE;
  116.         }
  117.         }
  118.         $cnt1++;
  119.     }
  120.  
  121.     # Execute the filesystem resources
  122.     &Status("Executing the $FILESYSTEM resource scripts, I.e. probe, exclusive, start, monitor and stop");
  123.     &Status("Please be patient ...");
  124.     foreach $script (@HA_LIST) {
  125.     $retv=ExecuteScript($node,$resource,$FILESYSTEM,$script);
  126.     if ($retv == 0) {
  127.         # script failed, exit
  128.         return $CD_FAILURE;
  129.     }
  130.     # Sleep a while
  131.     sleep(3);
  132.     }
  133.     
  134.     # Stop all dependencies
  135.     $cnt1=0;
  136.     foreach $dependency1 (@depend1) {
  137.         # Check that the dependency is set, if so start it
  138.         if ($dependency1=~/$VOLUME/) {
  139.         $retv=ExecuteScript($node,$depend1[$cnt1+1],$VOLUME,$HA_STOP);
  140.         if ( $retv == 0 ) {
  141.         &Failure("Cannot stop $FILESYSTEM resource dependency $depend1[$cnt1+1] of type $VOLUME");
  142.         return $CD_FAILURE;
  143.         }
  144.         }
  145.         $cnt1++;
  146.     }
  147.     return $CD_SUCCESS;
  148. }
  149.  
  150. # TestFilesystem
  151. # The resource test has three parts
  152. #   1) Check the resource parameters.
  153. #   2) If the resource has dependencies check them.
  154.  
  155. sub TestFilesystem {
  156.   local ($machine, $resource) = @_;
  157.   local ($retv);
  158.   local ($volume, $options, $level);
  159.   local (@parameters,@depend);
  160.  
  161.   $retv=$CD_SUCCESS;
  162.  
  163.   &LogEntry();
  164.   &Status("Testing resource %s of resource type %s on node %s",
  165.        $resource,$FILESYSTEM,$machine_name);
  166.   
  167.   # Get the resource parameter list.
  168.   @parameters=&GetResParameters($machine,$FILESYSTEM,$resource);
  169.   if (scalar(@parameters) < 1 ) {
  170.     &Failure("No parameters found for resource %s of resource type %s",
  171.          $resource,$FILESYSTEM);
  172.     return $CD_FAILURE;
  173.   }
  174.  
  175.   if (@parameters[0] < 0){
  176.     &Failure("No parameters found for resource %s of type %s",
  177.          $resource,$FILESYSTEM);
  178.     return $CD_FAILURE;
  179.   }
  180.  
  181.   if (($volume=&pulloff("volume-name",@parameters)) eq "") {
  182.     &Failure("%s resource %s does not have the %s parameter set",
  183.          $FILEYSTEM,$resource,"volume-name");
  184.     $retv=$CD_FAILURE;
  185.   }
  186.  
  187.   if (($options=&pulloff("mount-options",@parameters)) eq "") {
  188.     &Failure("%s resource %s does not have the %s parameter set",
  189.          $FILESYSTEM,$resource,"mount-options");
  190.     $retv=$CD_FAILURE;
  191.   }
  192.  
  193.   # PV 676533 - Diags, scripts warn that filesystem does not 
  194.   #             have monitoring-level set.
  195.   if (($level=&pulloff("monitoring-level",@parameters)) eq "") {
  196.     &Notice("Default monitoring-level is assumed for the %s resource of resource type %s",
  197.         $resource,$FILESYSTEM);
  198.   }
  199.  
  200.   # Check the volume dependency, should be the same as the $volume
  201.   @depend=&GetResDependency($machine,$FILESYSTEM,$resource);
  202.  
  203.   if (scalar(@depend) < 1) {
  204.      &Failure("No dependencies returned for resource %s of resource type %s",
  205.          $resource,$FILESYTEM);
  206.      return $CD_FAILURE;
  207.   }
  208.  
  209.   if (@depend[0] < 0){
  210.     &Failure("No dependencies found for resource %s of resource type %s",
  211.          $resource,$FILESYSTEM);
  212.     return $CD_FAILURE;
  213.   }
  214.   
  215.   if (($depend[0] eq "$VOLUME") && ($depend[1] eq " ")){
  216.     &Failure("Resource %s does not have the %s dependency set",
  217.          $resource,$VOLUME);
  218.     $retv=$CD_FAILURE;
  219.   }
  220.      
  221.   if ($depend[1] ne $volume) {
  222.     &Failure("%s dependency %s is inconsistent with parameter %s",
  223.          $resource, $depend[1], $volume);
  224.     $retv=$CD_FAILURE;
  225.   }
  226.   
  227.   # Check that the found point exists in the node/host in question
  228.   $cmd="file $resource";
  229.   @output=&rsh($machine,$cmd);
  230.   if ($RSH_ERRNO != 0) {
  231.       $retv=$CD_FAILURE;
  232.   }
  233.   foreach $line (@output) {
  234.       if ($line =~ /.*(No such file or directory)/) {
  235.       &Failure("Resource %s of resource type %s does not have system mount point.",
  236.            $resource,$FILESYSTEM);
  237.       $retv=$CD_FAILURE;
  238.       }
  239.   }
  240.  
  241.   return $retv;
  242. }
  243.